package com.ja.openchat.ui.chat.multimsg;

import android.content.Context;
import android.content.Intent;
import android.os.Build;

import androidx.annotation.RequiresApi;

import com.ja.openchat.R;
import com.ja.openchat.ui.chat.ForwardActivity;
import com.zy.openchat.core.model.message.ChatInfo;
import com.zy.openchat.core.model.message.MessageInfo;
import com.zy.openchat.core.model.message.UiMessage;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class ForwardMessageAction extends MultiMessageAction {
    @RequiresApi(api = Build.VERSION_CODES.N)
    @Override
    public void onClick(List<UiMessage> messages) {
//        new MaterialDialog.Builder(fragment.getActivity())
//            .items("逐条转发", "合并转发")
//            .itemsCallback((dialog, itemView, position, text) -> {
//                switch (position) {
//                    case 0:
//                        forwardOneByOne(messages);
//                        break;
//                    case 1:
//                        forward(messages);
//                        break;
//                    default:
//                        break;
//                }
//            })
//            .build()
//            .show();
        forwardOneByOne(messages);
    }

    @RequiresApi(api = Build.VERSION_CODES.N)
    private void forwardOneByOne(List<UiMessage> messages) {
        ArrayList<MessageInfo> msgs = messages.stream().map(uiMessage -> uiMessage.message).collect(Collectors.toCollection(ArrayList::new));
        Intent intent = new Intent(fragment.getContext(), ForwardActivity.class);
        intent.putExtra("messages", msgs);
        fragment.startActivity(intent);
    }

    private void forward(List<UiMessage> messages) {
//        Toast.makeText(fragment.getActivity(), "合并转发", Toast.LENGTH_SHORT).show();
//        CompositeMessageContent content = new CompositeMessageContent();
//        String title;
//        if (conversation.type == Conversation.ConversationType.Single) {
//            UserInfo userInfo1 = ChatManager.Instance().getUserInfo(ChatManager.Instance().getUserId(), false);
//            UserInfo userInfo2 = ChatManager.Instance().getUserInfo(conversation.target, false);
//            title = userInfo1.displayName + "和" + userInfo2.displayName + "的聊天记录";
//        } else {
//            title = "群的聊天记录";
//        }
//        content.setTitle(title);

//        ArrayList<MessageInfo> msgs = messages.stream().map(uiMessage -> uiMessage.message).collect(Collectors.toCollection(ArrayList::new));
//        Intent intent = new Intent(fragment.getContext(), ForwardActivity.class);
//        intent.putExtra("messages", msgs);
//        fragment.startActivity(intent);
    }

    @Override
    public int iconResId() {
        return R.drawable.menu_zhuanfa_selector;
    }

    @Override
    public String title(Context context) {
        return context.getString(R.string.forward_text);
    }

    @Override
    public boolean filter(ChatInfo conversation) {
        return false;
    }
}
